# coding:utf-8
# 文件分析-统计字符出现此次与频率
# 2017-1-24 22:54:35
# v：0.1

import json
# import os

# 配置：
config = {"mode": 0,
          "path": "F:\\py_test\\小说\\诛仙.txt",
          # 'path':'./pyFile.txt',
                  "keyword": None,

          }
# 忽略统计的字符
ig = ['\n', ' ', '\t']
# 数据分析结果
saData = {}
# 获取一个文件全部内容


def fGet(fileUrl):
    fp = open(fileUrl, errors='ignore')
    if not fp:
        print('文件路径错误')
    fStr = fp.read()
    fp.close()
    return fStr

# aa = fGet('./pyFile.txt')
# print(aa)
# 写入文件


def fPut(fileUrl, wStr, mode='a'):
    fp = open(fileUrl, mode)
    if not fp:
        print('文件写入失败')
    wRes = fp.write(wStr)
    fp.close()
    return wRes


res = fGet(config['path'])
i = 0
for x in res:
    if x in ig:
        continue
    if x in saData:
        saData[x] += 1
    else:
        saData[x] = 1

sRes = json.dumps(saData, ensure_ascii=False, indent=4)
rs = fPut('./anaDat.txt', sRes)
print(rs)
